<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* .checkAll:checked {
            display: none;
        } */
    </style>
</head>

<body>
    全选：<input class="checkAll" type="checkbox">
    <div class="checkbox">
        <input class="ck" type="checkbox">
        <input class="ck" type="checkbox">
        <input class="ck" type="checkbox">
    </div>
    <script>
        const checkAll = document.querySelector('.checkAll');
        console.log(checkAll);
        const checkbox = document.querySelectorAll('.checkbox input');
        console.log(checkbox);
        //全选按钮
        //设置点击事件
        //每次判断布尔值，为true让小按钮全选
        checkAll.addEventListener('click', function () {
            console.log(this.checked);
            for (let i = 0; i < checkbox.length; i++) {
                checkbox[i].checked = this.checked;
            }
        })
        //反选按钮
        //点击事件
        //利用checked选择器判断
        for (let i = 0; i < checkbox.length; i++) {
            checkbox[i].addEventListener('click', function () {
                console.log(document.querySelectorAll('.ck:checked').length);
                console.log(document.querySelectorAll('.ck:checked').length === checkbox.length);
                checkAll.checked = document.querySelectorAll('.ck:checked').length === checkbox.length;
            })
        }

    </script>
</body>

</html>